#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/6/15 14:29
# @Author  : fuchen'en
# @Description:
import pika
import sys

credentials = pika.PlainCredentials('test', 'test123')
parameters = pika.ConnectionParameters(host='10.0.20.66',
                                       port='5672',
                                       virtual_host='/',
                                       credentials=credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()

# 采用直连模式，让交换机给指定的路由发送消息
channel.exchange_declare(exchange='direct_logs', exchange_type='direct')

severity = sys.argv[1] if len(sys.argv) > 1 else 'info'
message = ' '.join(sys.argv[2:]) or 'Hello World!'
channel.basic_publish(exchange='direct_logs', routing_key=severity, body=message)
print(' [x] Sent {!r}:{!r}'.format(severity, message))
connection.close()
